﻿@using NetCoreCMS.Models;
@using NetCoreCMS.Common;
@inject NetCoreCMS.IServices.IArticleService _article;
@{
    Layout = "~/Areas/admin/Views/Shared/_LayoutList.cshtml";
    ViewBag.Title = "评论管理";
    List<Article_comment> list = ViewData["list"] as List<Article_comment>;
    List<SelectListItem> propertyList = new List<SelectListItem>() {
      new SelectListItem(){ Text="所有属性", Value=""},
      new SelectListItem(){ Text="未审核", Value="isLock"},
      new SelectListItem(){ Text="已审核", Value="unLock"}
   };
}
@section HeaderContent{
    <script>
      function getQueryParam() {
         var text = $("#txtKeywords").val();
         var pageCount = $("#txtPageNum").val();
         var property = $("#ddlProperty").val();
         return "channel_id=@ViewBag.ChannelId&keywords=" + text + "&pagesize=" + pageCount + "&property=" + property;
      }
      //查询数据
      function search() {
         document.location = "index?" + getQueryParam();
      }

      //ExePostBack回调函数
      function __doPostBack(objId) {
         if (objId == "btnAudit") {
            submitAudit();
         }
         if (objId == "btnDelete") {
            submitdelete();
         }
      }

      //批量删除
      function submitdelete() {
         var $row = $("#ltable tr:gt(0)");
         var json = { list: [] };
         $($row).each(function (i, item) {
            if ($(item).find("input:checkbox").prop("checked")) {
               var id = $(item).find("td:eq(0)").find("label:eq(0)").text();
               var obj = { id: id };
               json.list.push(obj);
            }
         });
         $.ajax({
            url: "SubmitDelete?" + getQueryParam(),
            type: "POST",
            dataType: "html",
            data: "json=" + JSON.stringify(json),
            success: function (data) {
               eval(data);
            },
            error: function () {
               alert("删除数据失败!");
            }
         });
      }

      //批量审核
      function submitAudit() {
         var $row = $("#ltable tr:gt(0)");
         var json = { list: [] };
         $($row).each(function (i, item) {
            if ($(item).find("input:checkbox").prop("checked")) {
               var id = $(item).find("td:eq(0)").find("label:eq(0)").text();
               var obj = { id: id };
               json.list.push(obj);
            }
         });
         $.ajax({
            url: "SubmitAudit?" + getQueryParam(),
            type: "POST",
            dataType: "html",
            data: "json=" + JSON.stringify(json),
            success: function (data) {
               eval(data);
            },
            error: function () {
               alert("审核数据失败!");
            }
         });
      }

      //保存排序
      function submitSave() {
         //遍历表格行设置Json数据
         var $tr = $("#ltable tr:gt(0)");
         var json = { list: [] };
         $($tr).each(function (i, item) {
            var id = $(item).find("td:eq(0)").find("label:eq(0)").text();
            var sortId = $(item).find(".sort").val();
            var obj = { id: id, sortId: sortId };
            json.list.push(obj);
         });
         // 提交保存排序字段
         $.ajax({
            url: "SubmitSave?" + getQueryParam(),
            type: "POST",
            dataType: "html",
            data: "json=" + JSON.stringify(json),
            success: function (data) {
               eval(data);
            },
            error: function(){
               alert("保存排序失败!");
            }
         });
      }
    </script>
}
<form id="form1" method="post" action="#">
    <!--导航栏-->
    <div class="location">
        <a href="javascript:history.back(-1);" class="back"><i class="iconfont icon-up"></i><span>返回上一页</span></a>
        <a href="../center/index"><i class="iconfont icon-home"></i><span>首页</span></a>
        <i class="arrow iconfont icon-arrow-right"></i>
        <span>内容管理</span>
        <i class="arrow iconfont icon-arrow-right"></i>
        <span>评论列表</span>
    </div>
    <!--/导航栏-->
    <!--工具栏-->
    <div id="floatHead" class="toolbar-wrap">
        <div class="toolbar">
            <div class="box-wrap">
                <a class="menu-btn"><i class="iconfont icon-more"></i></a>
                <div class="l-list">
                    <ul class="icon-list">
                        <li><a href="javascript:;" onclick="checkAll(this);"><i class="iconfont icon-check"></i><span>全选</span></a></li>
                        <li><a href="javascript:;" id="btnAudit" onclick="ExePostBack('btnAudit','审核通过后将在前台显示，是否继续？');"><i class="iconfont icon-survey"></i><span>审核</span></a></li>
                        <li><a href="javascript:;" id="btnDelete" onclick="ExePostBack('btnDelete');"><i class="iconfont icon-delete"></i><span>删除</span></a></li>
                    </ul>
                    <div class="menu-list">
                        <div class="rule-single-select">
                            @Html.DropDownList("ddlProperty", new SelectList(propertyList, "Value", "Text", ViewBag.Property as string))
                        </div>
                    </div>
                </div>
                <div class="r-list">
                    <input type="text" id="txtKeywords" class="keyword" value="@ViewBag.Keywords" />
                    <a href="javascript:search();" id="lbtnSearch" class="btn-search"><i class="iconfont icon-search"></i></a>
                </div>
            </div>
        </div>
    </div>
    <!--/工具栏-->
    <!--列表-->
    <div class="table-container">
        <table width="100%" border="0" cellspacing="0" cellpadding="0" class="ltable" id="ltable">
            @foreach (Article_comment dr in list)
            {
                <tr>
                    <td class="comment">
                        <div class="title">
                            <span class="note"><i>@dr.user_name</i><i>@dr.add_time</i><i class="reply"><a href="../comment_edit/index?id=@dr.id">回复</a></i></span>
                            <b>
                                <span class="checkall" style="vertical-align:middle;">
                                    <input type="checkbox" />
                                </span>
                                <label style="display:none">@dr.id</label>
                            </b>
                            @{
                                string atitle = "删除";
                                var article = _article.GetModel(dr.article_id);
                                if (article != null)
                                    atitle = article.title;
                            }
                            @(atitle)
                        </div>
                        <div class="ask">
                            @if (dr.is_lock == 1)
                            {
                                <b class="audit" title="待审核"></b>
                            }
                            else
                            {
                                @dr.content
                            }
                            @if (dr.is_reply == 1)
                            {
                                <div class="answer"><b>管理员回复：</b>@dr.reply_content<span class="time">@dr.reply_time</span></div>
                            }
                        </div>
                    </td>
                </tr>
            }
            @if (list.Count == 0)
            {
                <tr><td align="center">暂无评论信息</td></tr>
            }
        </table>
    </div>
    <!--/列表-->
    <!--内容底部-->
    <div class="line20"></div>
    <div class="pagelist">
        <div class="l-btns">
            <span>显示</span>
            <input type="text" id="txtPageNum" class="pagenum" onkeydown="return checkNumber(event);" onchange="search();" value="@ViewBag.PageSize" />
            <span>条/页</span>
        </div>
        <div class="default">@Html.Raw(@ViewBag.PageContent)</div>
    </div>
    <!--/内容底部-->

</form>
